import { version } from "../../package.json";

const tabChange = () => {
  // 拥有两种字符串枚举值（'visible' 和 'hidden'）
  if (window.document.visibilityState === "visible") {
    console.log("123123123");
    const localVersion = localStorage.getItem("versioninfo");
    if (localVersion) {
      const info = JSON.stringify(localVersion);
      // 版本不一致就更新版本号，提示用户刷新页面
      if (info.version !== version) {
        localStorage.setItem("versioninfo", JSON.stringify(version));
      }
    } else {
      localStorage.setItem("versioninfo", JSON.stringify(version));
    }
  }
};
export function appVersionControl() {
  window.document.addEventListener("visibilitychange", tabChange);
}
